package cn.edu.scau.cmi.zhuangjunsheng.Client;



import cn.edu.scau.cmi.zhuangjunsheng.singleton.Chairman;



import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class SingletonClient extends Application{
	
	private TextField nameField = new TextField();
	private Button build = new Button("创建");
	private Label label;
	BorderPane Pane = new BorderPane();
	VBox vBox = new VBox(15);
	
	public static void main(String[] args) {
		launch(args);
	}
	
	public void start(Stage primaryStage) {
		// TODO Auto-generated method stub
		vBox.setPadding(new Insets(50,100,100,100));
		vBox.getChildren().add(new Label("请输入要创建的主席名字:"));
		vBox.getChildren().add(nameField);
		vBox.getChildren().add(build);
		//gridPane.add(build, 2, 2);
		
		
		build.setOnAction(e -> setName());
		
		Pane.setTop(vBox);
		Scene scene = new Scene(Pane,600,500);
		primaryStage.setTitle("单例模式");
		primaryStage.setScene(scene);
		primaryStage.show();
	}
	
	private void setName() {
		Chairman chairman = Chairman.getInstance(nameField.getText());
		//System.out.println(chairman);
		label = new Label("当前主席是：" + chairman.getName() + " " +  chairman.toString());
		vBox.getChildren().add(label);
	}
	
}
